package com.wwu.client;

import com.wwu.common.WsConst;
import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import javax.xml.namespace.QName;

@Slf4j
public class ClientTest {
    public static void main(String[] args) {
        //初始化JaxWs动态客户端工厂
        JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
        //设置Webservice访问地址
        Client client = factory.createClient("http://localhost:8081/THWebService/EmrDictService?wsdl");
        //设置客户端请求拦截器
        client.getOutInterceptors().add(new ClientLoginInterceptor("admin","123456"));
        HTTPConduit conduit = (HTTPConduit) client.getConduit();
        HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
        //设置请求超时时间（2秒）
        clientPolicy.setConnectionRequestTimeout(2000);
        //设置服务响应时间
        clientPolicy.setReceiveTimeout(120000);
        conduit.setClient(clientPolicy);
        try {
            Object[] objects = new Object[0];
            //invoke方法的第一个参数为请求的方法，第二个~第N个分别是对应的参数
            QName operationName = new QName(WsConst.NAMESPACE_URI,"getDiagDictInfo");
            objects = client.invoke(operationName,"","弥漫性腹膜炎","","","","","json");

            log.info("返回数据========："+objects[0]);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
